﻿using Absky.Enum;

namespace Absky.Util
{
    /// <summary>
    /// 浏览器帮助类
    /// </summary>
    public class BrowserHelper
    {
        /// <summary>
        /// 获取浏览器信息
        /// </summary>
        /// <param name="userAgent"></param>
        /// <returns>名称 版本号</returns>
        public static string GetBrwoserInfo(string userAgent)
        {
            var ie = new InternetExplorerBrowser(userAgent);
            if (ie.Type == BrowserTypeEnum.IE)
                return string.Format("{0} {1}", ie.Type.ToString(), ie.Version);
            var firefox = new FirefoxBrowser(userAgent);
            if (firefox.Type == BrowserTypeEnum.Firefox)
                return string.Format("{0} {1}", firefox.Type.ToString(), firefox.Version);
            var edge = new EdgeBrowser(userAgent);
            if (edge.Type == BrowserTypeEnum.Edge)
                return string.Format("{0} {1}", edge.Type.ToString(), edge.Version);
            var opera = new OperaBrowser(userAgent);
            if (opera.Type == BrowserTypeEnum.Opera)
                return string.Format("{0} {1}", opera.Type.ToString(), opera.Version);
            var chrome = new ChromeBrowser(userAgent);
            if (chrome.Type == BrowserTypeEnum.Chrome)
                return string.Format("{0} {1}", chrome.Type.ToString(), chrome.Version);
            var safari = new SafariBrowser(userAgent);
            if (safari.Type == BrowserTypeEnum.Safari)
                return string.Format("{0} {1}", safari.Type.ToString(), safari.Version);
            return string.Empty;
        }
    }
}
